//从集合的角度考虑事件

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
using LL = long long;
int n;
const int mod = 998244353;

int qmi(int a, int b, int p)
{
    LL res = 1;
    while(b)
    {
        if( b & 1 ) res =  res * a % p;
        a = (LL)a * a % p;
        b >>= 1;
    }
    return res;
}

int main()
{
    cin >> n;
    int res = 0;
    while(n--)
    {
        int x, y;
        cin >> x >> y; 
        res = (res + 1ll) * y % mod * qmi(y - x, mod - 2, mod) % mod;
    }
    cout << res << endl;
    return 0;
}